package com.znsd.stu.controllor;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.znsd.entitys.Leave;
import com.znsd.entitys.ShiftDuty;
import com.znsd.entitys.Cwj_SpecialtyInfo;
import com.znsd.entitys.Users;
import com.znsd.stu.service.Cwj_ShiftDutyService;
import com.znsd.stu.service.Cwj_UserService;

@Controller
public class Cwj_ShiftDutyControllor {
	@Autowired
	private Cwj_ShiftDutyService shift;
	@Autowired
	private Cwj_UserService users;
	
	@ResponseBody
	@RequestMapping("shiftList")
	public Map<String,Object> shiftList(HttpServletRequest  request) {
		HttpSession session =request.getSession();
		Integer classId=(Integer) session.getAttribute("classId");
		List<ShiftDuty> shiftInfo=shift.getShiftByClass(classId);
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("rows",shiftInfo);
		map.put("total",shiftInfo.size());
		return map;
	}
	
	@RequestMapping(value = "goSqUpdateStuByClass", method = RequestMethod.GET)
	public String goleave(Integer classId,HttpServletRequest  request) {
		HttpSession session=request.getSession();
		session.setAttribute("classId",classId);
		return "admin/shiftduty";
	}
	@RequestMapping(value = "updateShiftDuty", method = RequestMethod.GET)
	public String updateShiftDuty(Integer lid,Integer state,HttpServletRequest  request) {
		HttpSession session = request.getSession();
		Users user=(Users) session.getAttribute("user");
		System.out.println(lid);
		shift.update(lid, state, user.getUser_id());
		ShiftDuty shiftInfo=shift.getById(lid);
		System.out.println(shiftInfo);
		if(state==1) {
			users.updateStuByClassPost(shiftInfo.getNewclassid().getClazz_id(),shiftInfo.getUser_id().getUser_id());
		}
		
		return "admin/leaves";
	}
}
